package com.xbongbong.saas.model;
import com.xbongbong.paas.toolbox.exception.XbbException;
import com.xbongbong.saas.domain.entity.ProductStockUpdateEntity;
import com.xbongbong.saas.domain.entity.ProductWarehouseEntity;

import java.util.Collection;
import java.util.List;
import java.util.Map;
import java.util.Set;

/**
 * 产品库存
 * @author Jian.Wang
 * @date 2019/2/17
 * @since v1.0
 * @version v1.0
 */
public interface ProductWarehouseModel {


    Integer deleteByIdIn(String corpid, List<Long> idIn) throws XbbException;

    Integer deleteByProductIdIn(String corpid, List<Long> productIdIn) throws XbbException;

    ProductWarehouseEntity getByKey(Integer key, String corpid);

//    List<ProductWarehouseEntity> findEntitys(Map<String, Object> param);

    List<ProductWarehouseEntity> findEntitysWithWarehouseChecked(Map<String, Object> param,Integer warehouseChecked);

    Integer getEntitysCount(Map<String, Object> param);

    Integer updateWarehouseNameByWarehouseId(String warehouseName, String corpid, long warehouseId);

    Map<Long,ProductWarehouseEntity> getWarehouseProductList(String corpid, Long warehouseId, List<Long> productIds, List<String> fieldList) throws XbbException;

    Map<Long, List<ProductWarehouseEntity>> getWarehouseProductMap(String corpid, List<Long> productIds, List<String> fieldList) throws XbbException;

    Map<Long, List<ProductWarehouseEntity>> getWarehouseProductMapByParentIdIn(String corpid, List<Long> parentIdIn, List<String> fieldList) throws XbbException;


    /**
     * 批量插入
     * @param productWarehouseList
     */
    void insertBatch(List<ProductWarehouseEntity> productWarehouseList) throws XbbException;

    void insertBatchImmediately(List<ProductWarehouseEntity> productWarehouseList) throws XbbException;


    /**
     * 只更新库存和成本，别乱加字段
     * @param productWarehouseEntityList
     * @param corpid
     */
    void updateStockBatch(List<ProductWarehouseEntity> productWarehouseEntityList, String corpid) throws XbbException;

    /**
     * 获取idList
     * @param corpid
     * @param productIdIn
     * @return
     */
    List<ProductWarehouseEntity> getIdList(String corpid, List<Long> productIdIn);



    void deleteByIdInAndParentId(String corpid, List<ProductWarehouseEntity> delProductWarehouseIdList) throws XbbException;

    List<ProductWarehouseEntity> getProductWareHouseByParentIdAndWarehouseIdIn(String corpid, Long parentId, List<Long> warehouseIdIn, List<String> fieldList, Integer isNotify) throws XbbException;


    Integer deleteBatch(String corpid, List<ProductWarehouseEntity> productWarehouseEntityList) throws XbbException;

    List<ProductWarehouseEntity> findEntitysForUpdate(Map<String, Object> map);

    void updateStockDB(Set<String> warehouseKeyList, Collection<ProductStockUpdateEntity> values, String corpid, Boolean isFromOri) throws XbbException;

//    List<String> getExistWarehouseKeyList(String corpid, Set<String> warehouseKeyList);

    /**
     * 更新预警信息
     * @param needUpdateNotifyWarehouseEntityList
     * @param corpid
     */
    void updateBatchNotifyMaybeCost(List<ProductWarehouseEntity> needUpdateNotifyWarehouseEntityList, String corpid) throws XbbException;
    List<String> getExistWarehouseKeyList(String corpid, Set<String> warehouseKeyList, Integer warehouseChecked);

    /**
     * 根据warehouseKey判断是否存在
     *
     * @param corpid
     * @param warehouseKeyList
     * @param warehouseChecked
     * @return
     */
    List<ProductWarehouseEntity> getExistProductWarehouseList(String corpid, Set<String> warehouseKeyList, Integer warehouseChecked);

    /**
     * 解绑仓库
     * @param corpid
     * @param unbundleList
     */
    void unbundleWarehouse(String corpid, List<ProductWarehouseEntity> unbundleList) throws XbbException;

    /**
     * 恢复绑定仓库
     * @param corpid
     * @param rebundleList
     */
    void rebundleWarehouse(String corpid, List<ProductWarehouseEntity> rebundleList) throws XbbException;

    void reSetOriNum(List<Long> productWarehouseIdList, String corpid);

    List<String> getCorpidList();

    void updateProductWarehouseById(List<ProductWarehouseEntity> productWarehouseEntityList, String corpid);

    List<ProductWarehouseEntity> findProductWarehouse(List<Long> prodcutIdList, String corpid);

    List<ProductWarehouseEntity> listByProductIdInAndWarehouseIdIn(String corpid, List<Long> productIdIn, List<Long> warehouseIdIn) throws XbbException;

    List<ProductWarehouseEntity> listByProductIdInWasehouseIn(String corpid, List<String> warehouseKey);

    List<ProductWarehouseEntity> getCostIsNullWarehouseKey(String corpid, List<Long> productIdList);

}
